package com.example.helloworld.util;

import java.io.IOException;
import java.io.InputStream;
import java.util.Scanner;

import android.content.Context;

public class ResourceUtil {

	private ResourceUtil() {}
	
	public static String getRawStringResource(Context applicationContext, int resourceId) {
		StringBuffer result =		null;
		InputStream inputStream =	null;
		
		try {
			inputStream =		applicationContext.getResources().openRawResource(resourceId);
			Scanner scanner =	new Scanner(inputStream, "UTF-8");
			scanner.useDelimiter(System.getProperty("line.separator"));
			while (scanner.hasNext()) {
				if (result == null) {
					result =	new StringBuffer();
				}
				result.append(scanner.next());
			}
			scanner.close();
		} catch (Exception e) {
			e.printStackTrace();
			result =	null;		
		} finally {
			if (inputStream != null) {
				try { inputStream.close(); } catch (IOException e) { e.printStackTrace(); }
			}
		}
		
		return (result == null ? null : result.toString());
	}
		
}
